﻿using AutoMapper;
using B.S.Packaged.Domain.Tree;
using B.S.Packaged.ErrorCode;
using B.S.Packaged.Infra;
using B.S.Packaged.WebAPI.Read.Application.Command.Workshop;
using B.S.Packaged.WebAPI.Read.Dtos;
using MediatR;
using SqlSugar;

namespace B.S.Packaged.WebAPI.Read.Application.CommandHander.Workshop
{
    public class GetWorkshopHander : IRequestHandler<GetWorkshopCommand, APIResult<List<Domain.Tree.Workshop>>>
    {

        private readonly IMapper mapper;
        private readonly ISqlSugarClient db;
        private readonly IDapperContext dapper;

        public GetWorkshopHander(IMapper mapper, ISqlSugarClient db, IDapperContext dapper)
        {
            this.mapper = mapper;
            this.db = db;
            this.dapper = dapper;
        }

        public async Task<APIResult<List<Domain.Tree.Workshop>>> Handle(GetWorkshopCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<Domain.Tree.Workshop>> result = new APIResult<List<Domain.Tree.Workshop>>();

            var sql = $"SELECT * from Workshop";
            var entity = await dapper.QueryAsync<Domain.Tree.Workshop>(sql);

            result.code = APIResultCode.success;
            result.msg = APIResultCode.success.ToString();
            result.data = entity.ToList();

            return await Task.FromResult(result);
        }

        /// <summary>
        /// 显示车间列表
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
    }
}
